<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.org/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Title</title>
    <link rel="stylesheet" href="/resources/layui/css/layui.css">
</head>
<body>
<script src="/resources/layui/layui.js"></script>

<script th:inline="none">
    //一般直接写在一个js文件中
    layui.use(['layer', 'form','table'], function(){
        var layer = layui.layer
            ,form = layui.form
            ,table = layui.table
            ,$=layui.jquery;
        //引入表格，使用表格
        var userTable=table.render({
            elem:'#driverTable',
            height:600,
            url:'/driver/driverList',
            page:true,
            id:'driverListTable',
            limits:[5,10,15,20],
            limit:5,
            cols:[[
                {field:'id',title:'编号',width:80,type:'checkbox'},
                {field: 'name', title: '名字'},
                {field: 'entry', title: '入职日期'},
                {field: 'sex', title: '性别'},
                {field: 'telephone', title: '电话'},
                {field: 'address', title: '家庭地址'},
                {field: 'driving', title: '驾驶证编号'},
                {field: 'information', title: '驾驶员描述'},
                {field: 'status', title: '状态',templet:function (obj) {
                    return obj.status==1?"在职":"休假";
                }},
                {field: 'dept',title:'部门',templet:function (obj) {
                    return obj.dept.name;
                }},
                {field : 'dictionary',title:'驾照类型',templet:function (obj) {
                    return obj.dictionary.name;
                }},
                {title: '操作', width:250,templet:'#driverListBar',fixed:"right",align:"center"}
            ]]
        })
        //搜索功能
        $(".searchBtn").click(function () {
            console.log("999999999")
            var telephone=$("#telephone").val();
            var name=$("#name").val();
            table.reload("driverListTable",{url:'/driver/driverList?telephone='+telephone+"&name="+name})
        })
        //批量删除
        $("#removePatch").click(function () {
            //获取复选框的值
            var check=table.checkStatus("driverListTable")
            var data=check.data;
            var ids=new Array();
            if(data.length==0){
                layer.msg("至少选择一个")
            }else{
                for(var i=0;i<data.length;i++){
                    ids.push(data[i].id)
                }
                layer.confirm('确定删除用户',{icon:3,title:'提示信息'},function (delindex) {
                    $.ajax({
                        type:"post",
                        url:"/driver/deleteAllPath",
                        data:{ids:ids},
                        traditional:true,
                        success:function () {
                            //关闭提示框
                            layer.close(delindex)
                            //刷新表单
                            userTable.reload();
                        }
                    })
                })
            }
        })
    });
</script>

<blockquote class="layui-elem-quote quoteBox">
    <form class="layui-form" action="">
        <div class="layui-inline">
            <input type="text" class="layui-input" id="telephone" placeholder="请输入电话号码">
        </div>
        <div class="layui-inline">
            <input type="text" class="layui-input" id="name" placeholder="请输入姓名">
        </div>

        <div class="layui-inline">
            <button type="button" class="layui-btn searchBtn">
                搜索
            </button>
        </div>
        <div class="layui-inline">
            <shiro:hasPermission name="user:delectall">
                <button type="button" class="layui-btn" id="removePatch">
                    批量删除
                </button>
            </shiro:hasPermission>
        </div>
        <div class="layui-inline">
            <shiro:hasPermission name="user:add">
                <button type="button" class="layui-btn" id="addPatch">
                    增加
                </button>
            </shiro:hasPermission>
        </div>
    </form>
</blockquote>

<table id="driverTable" lay-filter="usersList">
    <!--操作-->
    <script id="driverListBar" type="text/html">
        <shiro:hasPermission name="user:edit">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        </shiro:hasPermission>

        <shiro:hasPermission name="user:delete">
            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
        </shiro:hasPermission>

        <shiro:hasPermission name="user:look">
            <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="look">预览</a>
        </shiro:hasPermission>

        <!--<shiro:hasPermission name="user:grant">-->
            <!--<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="grantRole">分配角色</a>-->
        <!--</shiro:hasPermission>-->
    </script>
</table>

</body>
</html>